package com.zhenglvhang.util;

import com.google.common.io.Resources;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

public class ResUtil {

    public static String getProperty(String resourceName, String key) {
        String property = null;
        URL resource = Resources.getResource(resourceName);
        Properties properties = new Properties();

        try {
            try (InputStream is = resource.openStream()) {
                properties.load(is);
            }
            property = properties.getProperty(key);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return property;
    }

    public static String getProperty(String key) {
        return getProperty("application.properties", key);
    }
}
